<?
require('bootstrap.php');
if (isset($_POST['config_in_post'])) {
	$_SESSION['config'] = $_POST;
	$goto_next_step = true;
}

?>
<html>
	<head>
		<title>Installation af KomitCMS</title>
		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<link rel="stylesheet" type="text/css" href="../stylesheet/style.css" />
		<link rel="stylesheet" type="text/css" href="../stylesheet/install.css" />
		<script type="text/javascript">
			<? 
				if ($goto_next_step) { 
					echo 'parent.nextStep();'; 
				} 
			?>
			function fieldEmpty(jField) {
				return (jField.value == '');
			}
			function fieldConfirm(jField1, jField2) {
				return (jField1.value != jField2.value);
			}
			function setError(jField) {
				jField.style.border = '1px solid #FF0000';
			}
			function clearFields(jForm) {
				for(var i=0; i<jForm.elements.length; i++) {
					var jEl = jForm.elements[i];
					if (jEl.type == 'text' || jEl.type == 'password') {
						jEl.style.border = '';
					}
				}
			}
			function submitForm() {
				var jForm = document.forms[0];
				clearFields(jForm);
				var jErrors = Array();
				if (fieldEmpty(jForm['site_name'])) {
					jErrors.push('site_name');
				}
				if (fieldEmpty(jForm['site_index'])) {
					jErrors.push('site_index');
				}
				if (fieldEmpty(jForm['first_name'])) {
					jErrors.push('first_name')
				}
				if (fieldEmpty(jForm['last_name'])) {
					jErrors.push('last_name');
				}
				if (fieldEmpty(jForm['username'])) {
					jErrors.push('username');
				}
				if (fieldEmpty(jForm['password'])) {
					jErrors.push('password');
				}
				if (fieldConfirm(jForm['password'], jForm['confirm'])) {
					jErrors.push('confirm');
				}
				if (jErrors.length > 0) {
					for (var i=0; i<jErrors.length; i++) {
						setError(jForm[jErrors[i]]);
					}
					return false;
				}
				jForm.submit();
			}
			function nextStep() {
				submitForm();
			}
		</script>
	</head>
	
	<body style="margin: 0">
		<div id="control">
			<button onclick="//parent.previousStep()">Forige</button>
			<button onclick="nextStep()">Næste</button>
		</div>
		<h2 class="page-header">Konfiguration</h2>
		<div id="description">
			I dette trin skal du udfylde informationer for selve siden/systemet, og den bruger du selv skal bruge. Når du har installeret systemet kan du oprette flere brugere.
		</div>
		<div id="step" style="margin-top: 10px; padding-top: 10px; border-top: 1px solid #CCC">
			<form method="post">
				<input type="hidden" name="config_in_post" value="1" />
				<table class="UI_Editor">
					<tr>
						<td class="label">Sidens navn: </td>
						<td><input type="text" name="site_name"/></td>
					</tr>
					<tr>
						<td class="label">
							Forsidens navn:<br/>
							<small>(Fx Forside eller Hjem)
						</td>
						<td>
							<input type="text" name="site_index" value="Forside" onclick="this.value=''"
								onblur="if(this.value == '') {this.value='Forside'}"/>
						</td>
					</tr>
					<tr style="height: 20px"></tr>
					<tr>
						<td class="label">Fornavn: </td>
						<td><input type="text" name="first_name" /></td>
					</tr>
					<tr>
						<td class="label">Efternavn: </td>
						<td><input type="text" name="last_name" /></td>
					</tr>
					<tr>
						<td class="label">Brugernavn: </td>
						<td><input type="text" name="username" /></td>
					</tr>
					<tr>
						<td class="label">Password: </td>
						<td><input type="password" name="password" /></td>
					</tr>
					<tr>
						<td class="label">Gentag: </td>
						<td><input type="password" name="confirm" /></td>
					</tr>
				</table>
			</form>
		</div>
	</body>
</html>